import dt from '@dt/dt'
import orderApi from '@/config/server/api/order.js'

function list(info) {
  return orderApi.bonus.year.list.fetch(info)
}

function create(info) {
  return orderApi.bonus.year.create.fetch(info)
}

function detail(bonusId) {
  return orderApi.bonus.year.detail.fetch({
    bonusId
  })
}

function detailList(info) {
  return orderApi.bonus.year.detailList.fetch(info)
}

function bonusDetail(info) {
  return orderApi.bonus.year.bonusDetail.fetch(info).then(res => {
    let data = res.map(i => ({
      ...i,
      adjustAmount: i.adjustAmount || 0,
      adjustBonusPool: i.adjustBonusPool || 0
    }))
    return data
  })
}

function updateDetail(info) {
  return orderApi.bonus.year.updateDetail.fetch(info)
}

function exportDetail(bonusId) {
  return orderApi.bonus.year.export.fetch({
    bonusId
  })
}

function download(info) {
  return orderApi.bonus.year.download.fetch(info)
}

function upload(bonusId) {
  let info = { bonusId }
  let upload = orderApi.bonus.year.upload
  upload.setData(info)
  return upload
}

function submit(bonusId) {
  return orderApi.bonus.year.submit.fetch({
    bonusId
  })
}

export default {
  list,
  create,
  detail,
  detailList,
  bonusDetail,
  updateDetail,
  exportDetail,
  download,
  upload,
  submit
}